package zero.tech.games.gate.topic;

import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;

import zero.tech.core.ZeroContext;
import zero.tech.core.data.Resp;
import zero.tech.games.common.Code;
import zero.tech.games.common.TUserAccountUtil;
import zero.tech.games.common.TopicOrder;
import zero.tech.games.entity.user.TUserAccount;
import zero.tech.games.gate.data.GATECMD;
import zero.tech.games.gate.util.PackageUtil;
import zero.tech.redis.topic.TopicChannelType;
import zero.tech.redis.topic.TopicProcess;
import zero.tech.wsnet.controller.CacheOnline;
import zero.tech.wsnet.controller.Controller;
import zero.tech.wsnet.data.Message;

public class DiamondChangeTopic extends TopicProcess{

	@Override
	public String orderType() {
		return TopicOrder.DIAMOND_CHANGE;
	}

	@Override
	public void process(String message) throws Exception {
		List<Integer> list=JSONObject.parseObject(message,new TypeReference<List<Integer>>() {});
		if(!list.isEmpty()) {
			TUserAccountUtil userAccountUtil =  ZeroContext.getInstance(TUserAccountUtil.class);
			for(Integer uid:list) {
				Controller controller=CacheOnline.getCache().getOnlines().get(uid);
				if(controller!=null&&controller.getWebClient()!=null&&controller.getWebClient().isAlive()) {
					TUserAccount userAccount=userAccountUtil.getUserAccount(uid);
					controller.getWebClient().sendMessage(Message.build(GATECMD.NOTIFY_DIAMOND_CHANGE, Resp.build(Code.OK, "砖石账户改变",PackageUtil.packageNotifyDiamondChange(userAccount))));
				}
			}
		}
	}

	@Override
	public TopicChannelType channelType() {
		return TopicChannelType.DIAMOND_CHANGE;
	}

}
